/**
 * ReportGear(2011)
 */
package com.reportgear.report.model.auxiliary;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;

/**
 * 列属性
 * 
 * @version 1.0 2011-3-12
 * @author <a herf="lexloo@gmail.com">lexloo</a>
 * @since Report 1.0
 * 
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "ColumnProp")
public final class ColumnProperty implements Cloneable {
    // 值，宽度或高度
    @XmlAttribute(name = "Width")
    private int width = 72;
    // 是否可见
    @XmlAttribute(name = "Visible")
    private boolean visible = true;
    // 类型
    @XmlAttribute(name = "Type")
    private ColumnType type = ColumnType.NORMAL;
    // 是否分组
    @XmlAttribute(name = "Group")
    private boolean group = false;
    // 默认列信息
    public static final ColumnProperty DEFAULT_COLUMN_PROPERTY = new ColumnProperty();

    public ColumnProperty() {
    }

    public void setType(String typeName) {
        this.setType(Enum.valueOf(ColumnType.class, typeName));
    }

    /**
     * 获取属性类型
     * 
     * @return 属性类型
     */
    public final ColumnType getType() {
        return this.type;
    }

    /**
     * 设置属性类型
     * 
     * @param type
     *            属性类型
     */
    public final void setType(ColumnType type) {
        this.type = type;
    }

    /**
     * 设置宽度
     * 
     * @param width 宽度
     * 
     */
    public void setWidth(int width) {
        this.width = width;
    }

    /**
     * 获取宽度
     * 
     * @return 宽度
     */
    public int getWidth() {
        return this.width;
    }

    /**
     * 设置是否分组
     * 
     * @param group
     *            是否分组
     */
    public void setGroup(boolean group) {
        this.group = group;
    }

    /**
     * @return 是否分组
     */
    public boolean isGroup() {
        return group;
    }

    /**
     * 设置是否可见
     * 
     * @param visible
     *            可见性
     */
    public void setVisible(boolean visible) {
        this.visible = visible;
    }

    /**
     * 获取是否可见
     * 
     * @return 是否可见
     */
    public boolean isVisible() {
        return visible;
    }

    @Override
    public ColumnProperty clone() {
        try {
            return (ColumnProperty) super.clone();
        } catch (CloneNotSupportedException e) {
            throw new InternalError();
        }
    }
}
